import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-06
 * Time: 22:18
 */
class Student2 implements Comparable<Student2>{
    String name;
    int age;
    double score;
    public Student2(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }
    @Override
    public String toString() {
        return "Student{" +
                "姓名='" + name + '\'' +
                ", 年龄=" + age +
                ", 成绩=" + score +
                '}';
    }
    //重写 Comparable 中的 compareTo 方法，当sort方法调用时会调用此方法，告诉sort方法根据类中什么属性进行比较
//    //根据年龄排序
//    @Override
//    public int compareTo(Student2 o) {
////        if(this.age < o.age) {
////            return -1;
////        } else if(this.age > o.age) {
////            return 1;
////        } else {
////            return 0;
////        }
//        return this.age - o.age;
//    }
   //根据姓名排序
//    @Override
//    public int compareTo(Student2 o) {
//        return o.name.compareTo(this.name);
//    }
    //根据分数排序
    @Override
    public int compareTo(Student2 o) {
        return (int) (this.score - o.score);
    }
}
//实现Comparato 接口 ,进行比较
public class Test03 {
    public static void main(String[] args) {
        Student2[] student = {
                new Student2("张三",18,60.5),
                new Student2("李四",25,78.5),
                new Student2("王五",10,45.25),
        };
        Arrays.sort(student);
        System.out.println(Arrays.toString(student));
    }
}
